﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.RBAC;
using MediatR;

namespace AuthCenter_API.Read.Applications.CommandHandlers.User
{
    public class XianQueryCommandHandler : IRequestHandler<XianQueryCommand, APIResult<List<XianModel>>>
    {
        private readonly IBaseRepository<XianModel> _xianRepository;

        public XianQueryCommandHandler(IBaseRepository<XianModel> xianRepository)
        {
            _xianRepository = xianRepository;
        }

        public Task<APIResult<List<XianModel>>> Handle(XianQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<XianModel>> result = new APIResult<List<XianModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _xianRepository.GetAll().Where(x => x.ShiId == request.ShiId).ToList();
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
